
from src.api import API

class InvisibleHandCLI:

    def __init__(self):
        self.api = API()

    def show_plugins(self):
        plugins = self.api.get_plugins()
        items = dict()
        for plugin in plugins:
            _, pitems = self.api.get_plugin_items(plugin.id)
            items[plugin] = pitems
        for plugin, pitems in items.items():
            print(plugin.name, plugin.id)
            for pitem in pitems:
                print(f"    {pitem.name}")
                print(f"        action: {pitem.action}")
                print(f"        input: {pitem.is_input_required}")

    def show_plugin_items(self, id):
        plugin, pitems = self.api.get_plugin_items(id)
        print(plugin.name, plugin.id)
        for pitem in pitems:
            print(f"    {pitem.name}")
            print(f"        action: {pitem.action}")
            print(f"        input: {pitem.is_input_required}")

    def do_plugin_action(self, id, action, uinput):
        result = self.api.do_plugin_action(id, action, uinput)
        print(f"{id}: {action} result: {result}")


